package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.CustomerTraceHistory;
import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.service.ICustomerTraceHistoryService;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.qo.JsonResult;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/customerTraceHistory")
public class CustomerTraceHistoryController {

    @Autowired
    private ICustomerTraceHistoryService customerTraceHistoryService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;


    @RequiresPermissions(value = {"customerTraceHistory:list", "客户跟进页面"}, logical = Logical.OR)
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") QueryObject qo, Long id) {
        qo.setCustomerId(id);
        PageInfo<CustomerTraceHistory> pageInfo = customerTraceHistoryService.query(qo);
        model.addAttribute("result", pageInfo);
        return "customerTraceHistory/list";
    }

   @RequestMapping("/update")
   @ResponseBody
   public JsonResult update(){
        return new JsonResult(true,"操作成功");
   }

   @RequestMapping("/sorejq")
   public void sor(){
       System.out.println("niubi");
       System.out.println("niubi");
       System.out.println("niubi");
       System.out.println("niubi");
   }
   @RequestMapping("/saveOrUpdate")
    @RequiresPermissions(value = {"customerTraceHistory:saveOrUpdate", "客户跟进新增/编辑"}, logical = Logical.OR)
    @ResponseBody
    public JsonResult saveOrUpdate(CustomerTraceHistory customerTraceHistory) {
        if (customerTraceHistory.getId() != null) {
            customerTraceHistoryService.update(customerTraceHistory);
        } else {
            customerTraceHistoryService.save(customerTraceHistory);
        }
        return new JsonResult(true, "操作成功");
    }

    @RequestMapping("/delete")
    @RequiresPermissions(value = {"customerTraceHistory:delete", "客户跟进删除"}, logical = Logical.OR)
    @ResponseBody
    public JsonResult delete(Long id) {
        if (id != null) {
            customerTraceHistoryService.delete(id);
        }
        return new JsonResult(true, "删除成功");
    }


    @RequestMapping("/eroiuawoire")
    public void ojojodjfo(){
        System.out.println("测试");
    }

}
